local controls_sel i.age_bin##female
local controls_out i.age_bin##female i.years_in_israel_bin##female

** First, run analysis that requires obs not in main sample, so we can drop afterward for faster runtime
*** Table A8 Sensitivity analysis
use "$path\Tempfiles\IsraeliCensus_vars.dta", clear
svyset serial [pweight=perwt_main], strata(new_strata) singleunit(scaled) fpc(sampling_rate)

gen exclude_35 = Imm == 1 & immigration_age < 35 //to exclude those arriving before 35
gen exclude_jewish = religion == 4 //to exclude jewish immigrants

**Construct linear pre-period trend
gen trend = (immigration_year_approx - 1989) * post_90
replace trend = 0 if Imm == 0
gen EB_trend = EB * (immigration_year_approx - 1960) if Imm == 1
gen WE_trend = (1 - EB) * (immigration_year_approx - 1960) if Imm == 1
gen prtt_edu_years = 0
reg edu_years EB_trend WE_trend i.birth_country `controls_sel' [pweight = perwt_main] if inrange(immigration_year_approx,1961,1986) & sample == 1
replace prtt_edu_years = _b[EB_trend] * trend if post_90 == 1 & EB == 1
replace prtt_edu_years = _b[WE_trend] * trend if post_90 == 1 & EB == 0
drop EB_trend WE_trend trend

svy: mean edu_years if sample == 1 & exclude_35!=1 & EB == 1
local depvar_mean_eb = e(b)[1,1]
svy, subpop(sample if exclude_35!=1): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\tb5_is.xls", replace label stats(coef se) nonotes dec(3) afmt(g) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)

svy: mean edu_years if sample == 1 & exclude_jewish!=1 & EB == 1
local depvar_mean_eb = e(b)[1,1]
svy, subpop(sample if exclude_jewish!=1): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\tb5_is.xls", append label stats(coef se) nonotes dec(3) afmt(g) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)

svy: mean edu_years if sample_allages == 1 & EB == 1
local depvar_mean_eb = e(b)[1,1]
svy, subpop(sample_allages): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\tb5_is.xls", append label stats(coef se) nonotes dec(3) afmt(g) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)

svy: mean edu_years if sample == 1 & EB == 1
local depvar_mean_eb = e(b)[1,1]
svy, subpop(sample): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year prtt_edu_years
outreg2 using "$path\Output\Israel\tb5_is.xls", append label stats(coef se) nonotes dec(3) afmt(g) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 prtt_edu_years) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 prtt_edu_years)

drop exclude_35 exclude_jewish prtt_edu_years sample_allages
 
erase "$path\Output\Israel\tb5_is.txt"


*** Fig 3 (Selection from origin using Bayes' rule) + Fig B2 + Fig B3
use "$path\Tempfiles\IsraeliCensus_vars.dta", clear
keep if EB==1
keep if year == 2008
cd "$path\Output\Israel"

svyset serial [pweight=perwt], strata(new_strata) singleunit(scaled) fpc(sampling_rate) //use year-specific weights here

* Poland
putexcel set israel_poland_all, replace

svy: tab isced_int if birth_country == 310 & birthyr >= 1946 & birthyr <= 1986 & immigration_age >= 25 & immigration_year_approx <= 2011 //age 25-65 as of 2011
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel A1=matrix(A)

svy: tab isced_int if birth_country == 310 & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 1986 //age 25-45 in 1970, hadn't migrated by 1970, migrated between 1970-1986
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel C1=matrix(A)

svy: tab isced_int if birth_country == 310 & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 2011 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel E1=matrix(A)

svy: tab isced_int if birth_country == 310 & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 1992 //age 25-45 in 1987, hadn't migrated by 1987, migrated between 1987-1992
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel G1=matrix(A)

svy: tab isced_int if birth_country == 310 & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 2011 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel I1=matrix(A)

svy: tab isced_int if birth_country == 310 & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2003  //age 25-45 in 1993, hadn't migrated by 1993, migrated between 1993-2003
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel K1=matrix(A)

svy: tab isced_int if birth_country == 310 & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2011  //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel M1=matrix(A)

* Romania
putexcel set israel_romania_all, replace

svy: tab isced_int if birth_country == 400  & birthyr >= 1946 & birthyr <= 1986 & immigration_age >= 25 & immigration_year_approx <= 2011 //age 25-65 as of 2011
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel A1=matrix(A)

svy: tab isced_int if birth_country == 400 & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 1986 //age 25-45 in 1970, hadn't migrated by 1970, migrated between 1970-1986
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel C1=matrix(A)

svy: tab isced_int if birth_country == 400  & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 2011 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel E1=matrix(A)

svy: tab isced_int if birth_country == 400 & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 1992 //age 25-45 in 1987, hadn't migrated by 1987, migrated between 1987-1992
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel G1=matrix(A)

svy: tab isced_int if birth_country == 400  & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 2011 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel I1=matrix(A)

svy: tab isced_int if birth_country == 400 & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2003  //age 25-45 in 1993, hadn't migrated by 1993, migrated between 1993-2003
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel K1=matrix(A)

svy: tab isced_int if birth_country == 400  & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2011  //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel M1=matrix(A)

* Romanian Jews
putexcel set israel_romania_jews, replace

svy: tab isced_int if birth_country == 400 & religion == 4  & birthyr >= 1946 & birthyr <= 1986 & immigration_age >= 25 & immigration_year_approx <= 2011 //age 25-65 as of 2011
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel A1=matrix(A)

svy: tab isced_int if birth_country == 400 & religion == 4 & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 1986 //age 25-45 in 1970, hadn't migrated by 1970, migrated between 1970-1986
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel C1=matrix(A)

svy: tab isced_int if birth_country == 400 & religion == 4  & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 2011 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel E1=matrix(A)

svy: tab isced_int if birth_country == 400 & religion == 4 & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 1992 //age 25-45 in 1987, hadn't migrated by 1987, migrated between 1987-1992
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel G1=matrix(A)

svy: tab isced_int if birth_country == 400 & religion == 4  & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 2011 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel I1=matrix(A)

svy: tab isced_int if birth_country == 400 & religion == 4 & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2003  //age 25-45 in 1993, hadn't migrated by 1993, migrated between 1993-2003
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel K1=matrix(A)

svy: tab isced_int if birth_country == 400 & religion == 4  & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2011  //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel M1=matrix(A)

* Russia 2010 census -- need to include "Former SU in Europe"
putexcel set israel_russia_all, replace

svy: tab isced_rus if inlist(birth_country,5,306) & birthyr >= 1946 & birthyr <= 1986 & immigration_age >= 25 & immigration_year_approx <= 2010 //age 25-65 as of 2011
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel A1=matrix(A)

svy: tab isced_rus if inlist(birth_country,5,306) & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 1986  //age 25-45 in 1970, hadn't migrated by 1970, migrated between 1970-1986
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel C1=matrix(A)

svy: tab isced_rus if inlist(birth_country,5,306) & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 2010  //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel E1=matrix(A)

svy: tab isced_rus if inlist(birth_country,5,306) & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 1992 //age 25-45 in 1987, hadn't migrated by 1987, migrated between 1987-1992
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel G1=matrix(A)

svy: tab isced_rus if inlist(birth_country,5,306) & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 2010 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel I1=matrix(A)

svy: tab isced_rus if inlist(birth_country,5,306) & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2003  //age 25-45 in 1993, hadn't migrated by 1993, migrated between 1993-2003
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel K1=matrix(A)

svy: tab isced_rus if inlist(birth_country,5,306) & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2010  //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel M1=matrix(A)

* Soviet Jews
putexcel set israel_russia_jews, replace

svy: tab isced_rus if Sov == 1 & religion == 4 & birthyr >= 1946 & birthyr <= 1986 & immigration_age >= 25 & immigration_year_approx <= 2010 //age 25-65 as of 2011
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel A1=matrix(A)

svy: tab isced_rus if Sov == 1 & religion == 4 & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 1986  //age 25-45 in 1970, hadn't migrated by 1970, migrated between 1970-1986
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel C1=matrix(A)

svy: tab isced_rus if Sov == 1 & religion == 4 & birthyr >= 1925 & birthyr <= 1945 & immigration_year_approx >= 1970 & immigration_year_approx <= 2010  //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel E1=matrix(A)

svy: tab isced_rus if Sov == 1 & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 1992 //age 25-45 in 1987, hadn't migrated by 1987, migrated between 1987-1992
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel G1=matrix(A)

svy: tab isced_rus if Sov == 1 & birthyr >= 1942 & birthyr <= 1962 & immigration_year_approx >= 1987 & immigration_year_approx <= 2010 //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel I1=matrix(A)

svy: tab isced_rus if Sov == 1 & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2003  //age 25-45 in 1993, hadn't migrated by 1993, migrated between 1993-2003
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel K1=matrix(A)

svy: tab isced_rus if Sov == 1 & birthyr >= 1948 & birthyr <= 1968 & immigration_year_approx >= 1993 & immigration_year_approx <= 2010  //for denominator
matrix A  = (e(Row)', hadamard(e(Prop),J(e(r),1,e(N_pop))))
putexcel M1=matrix(A)



** From this point on, we can work with a single dataset and drop unused obs
use "$path\Tempfiles\IsraeliCensus_vars.dta", clear
drop if sample == .
svyset serial [pweight=perwt_main], strata(new_strata) singleunit(scaled) fpc(sampling_rate)


*** Table 1 (Educational Attainment)
qui svy: mean edu_years if sample == 1 & EB == 1
local depvar_mean_eb = el(e(b),1,1)

* pre/post, 2 then 3 periods
svy, subpop(sample if max(native,EB)==1): reg edu_years EB_post_92 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\t1_is.xls", replace label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)',"depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90)

svy, subpop(sample if max(native,EB)==1): reg edu_years EB_post_92 EB_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\t1_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)',"depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90)

* DID vs Westerners, 2 then 3 periods, w/ and w/o country FE
svy, subpop(sample): reg edu_years EB_post_92 Imm_post_92 i.birth_country i.year
outreg2 using "$path\Output\Israel\t1_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)',"depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90)

svy, subpop(sample): reg edu_years EB_post_92 Imm_post_92 `controls_sel' i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\t1_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90)

svy, subpop(sample): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country i.year
outreg2 using "$path\Output\Israel\t1_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90)

svy, subpop(sample): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\t1_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 EB Imm_post_92 Imm_post_90)

erase "$path\Output\Israel\t1_is.txt"


*** Table 2 (Labor Market Outcomes)
local iter = 0
local append_replace "replace"

foreach outcome in employed high_occ high_med_occ log_income{

local iter = `iter' + 1

if `iter' == 2{
	local append_replace "append"
}

qui svy, subpop(sample if EB==1): mean `outcome'
local depvar_mean_eb = el(e(b),1,1)

svy, subpop(sample): reg `outcome' EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country i.year `controls_out'
outreg2 using "$path\Output\Israel\t2_is.xls", `append_replace' label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)
}

cap erase "$path\Output\Israel\t2_is.txt"


*** Table B1 -- sum stats

*pull subpop sizes in 100000s
qui svy, subpop(sample if native == 1): reg female 
	local obs_1 = e(N_sub)/100000
	local pop_1 = e(N_subpop)/100000
qui svy, subpop(sample if Imm == 1 & EB == 0): reg female 
	local obs_2 = e(N_sub)/100000
	local pop_2 = e(N_subpop)/100000
qui svy, subpop(sample if Sat == 1): reg female 
	local obs_3 = e(N_sub)/100000
	local pop_3 = e(N_subpop)/100000
qui svy, subpop(sample if Sov == 1): reg female 
	local obs_4 = e(N_sub)/100000
	local pop_4 = e(N_subpop)/100000
	
svy, subpop(sample if native == 1): mean immigration_age female married edu_years isced97_5a employed high_occ 
outreg2 using "$path\Output\Israel\tb1_is.xls", replace label stats(coef) nonotes noaster addstat("Subpop Obs (100000s)", `obs_1', "Subpop Size (100000s)", `pop_1') dec(2) adec(2)
svy, subpop(sample if Imm == 1 & EB == 0): mean immigration_age female married edu_years isced97_5a employed high_occ 
outreg2 using "$path\Output\Israel\tb1_is.xls", append label stats(coef) nonotes noaster addstat("Subpop Obs (100000s)", `obs_2', "Subpop Size (100000s)", `pop_2') dec(2) adec(2)
svy, subpop(sample if Sat == 1): mean immigration_age female married edu_years isced97_5a employed high_occ 
outreg2 using "$path\Output\Israel\tb1_is.xls", append label stats(coef) nonotes noaster addstat("Subpop Obs (100000s)", `obs_3', "Subpop Size (100000s)", `pop_3') dec(2) adec(2)
svy, subpop(sample if Sov == 1): mean immigration_age female married edu_years isced97_5a employed high_occ 
outreg2 using "$path\Output\Israel\tb1_is.xls", append label stats(coef) nonotes noaster addstat("Subpop Obs (100000s)", `obs_4', "Subpop Size (100000s)", `pop_4') dec(2) adec(2)

cap erase "$path\Output\Israel\tb1_is.txt"



*** Table B3 -- Mincer Returns
gen exper = age - edu_years - 6
gen exper2 = exper*exper

local append_replace replace
foreach outcome in employed high_occ high_med_occ log_income {
	svy, subpop(sample if EB == 1): reg `outcome' edu_years exper exper2 female i.year ${countries}
	outreg2 using "$path\Output\Israel\tb3_is.xls", `append_replace' label stats(coef se) nonotes dec(3) sortvar(edu_years) keep(edu_years) noaster
	local append_replace append
}
erase "$path\Output\Israel\tb3_is.txt"
drop exper exper2

*** Fig B4 -- dropping one origin country at a time
*order: poland romania bulgaria czech/hungary ukraine
local append_replace replace
foreach country in 310 400 980 982 305{
local iter = `iter' + 1
svy, subpop(sample if birth_country != `country'): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\figb4_is.xls", `append_replace' label stats(coef se) nonotes dec(3) sortvar(EB_post_92) keep(EB_post_92)
local append_replace append
}
svy, subpop(sample if birth_country != 5 & birth_country != 306): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\figb4_is.xls", append label stats(coef se) nonotes dec(3) sortvar(EB_post_92) keep(EB_post_92) //combine "russia" and "european former USSR"

erase "$path\Output\Israel\figb4_is.txt"


*** Table B4 Different measures of education
local iter = 0
local append_replace "replace"
foreach outcome in isced97_3 isced97_4 isced97_5b isced97_5a{
	
local iter = `iter' + 1

if `iter' == 2{
	local append_replace "append"
}
	svy: mean `outcome' if sample == 1 & EB_post_90 == 1 & EB_post_92 == 0 //want late refugee mean
	local depvar_mean_eb = e(b)[1,1]
	
	svy, subpop(sample): reg `outcome' EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
	outreg2 using "$path\Output\Israel\tb4_is.xls", `append_replace' label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)
}
erase "$path\Output\Israel\tb4_is.txt"


*** Table B6 Outcomes w/ education as control
local iter = 0
local append_replace "replace"

foreach outcome in employed high_occ high_med_occ log_income{

local iter = `iter' + 1

if `iter' == 2{
	local append_replace "append"
}

svy: mean `outcome' if sample == 1 & EB == 1
local depvar_mean_eb = el(e(b),1,1)

svy, subpop(sample): reg `outcome' EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_out' i.year i.edu_years
outreg2 using "$path\Output\Israel\tb6_is.xls", `append_replace' label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)
}

cap erase "$path\Output\Israel\tb6_is.txt"

*** Table B7 -- Sat/Sov separately & excluding recovery
svy: mean edu_years if sample == 1 & Sat == 1
local depvar_mean_eb = e(b)[1,1]
svy, subpop(sample if Sov == 0): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\tb7_is.xls", replace label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)

svy: mean edu_years if sample == 1 & Sov == 1
local depvar_mean_eb = e(b)[1,1]
svy, subpop(sample if Sat == 0): reg edu_years EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\tb7_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90) keep(EB_post_92 EB_post_90 Imm_post_92 Imm_post_90)

capture noisily erase "$path\Output\Israel\tb7_is.txt"


*** Table B9 -- Gender
gen EB_post_92_m = EB_post_92 * female==0
gen EB_post_90_m = EB_post_90 * female==0
gen Imm_post_92_m = Imm_post_92 * female==0
gen Imm_post_90_m = Imm_post_90 * female==0
gen EB_m = EB * female==0
gen Imm_m = Imm * female==0

local iter = 0
local append_replace "replace"
foreach outcome in employed high_occ high_med_occ log_income{
	
local iter = `iter' + 1

if `iter' == 2{
	local append_replace "append"
}

svy: mean `outcome' if sample == 1 & EB == 1
local depvar_mean_eb = e(b)[1,1]
svy, subpop(sample): reg `outcome' EB_post_92 EB_post_90 EB_post_92_m EB_post_90_m EB_m Imm_post_92 Imm_post_90 Imm_post_92_m Imm_post_90_m Imm_m i.birth_country `controls_out' i.year
outreg2 using "$path\Output\Israel\tb9_is.xls", `append_replace' label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)', "depvar_mean_eb", `depvar_mean_eb') sortvar(EB_post_92_m EB_post_90_m EB_post_92 EB_post_90) keep(EB_post_92_m EB_post_90_m EB_post_92 EB_post_90)
}

erase "$path\Output\Israel\tb9_is.txt"
drop EB_post_92_m EB_post_90_m Imm_post_92_m Imm_post_90_m EB_m Imm_m


*** Table D1 -- restructuring (heterogeneous effects)

* Selection+Outcomes by gender
gen EB_post_92_m = EB_post_92 * female==0
gen EB_post_90_m = EB_post_90 * female==0
gen Imm_post_92_m = Imm_post_92 * female==0
gen Imm_post_90_m = Imm_post_90 * female==0
gen EB_m = EB * female==0
gen Imm_m = Imm * female==0

svy, subpop(sample): reg edu_years EB_post_92 EB_post_90 EB_post_92_m EB_post_90_m EB_m Imm_post_92 Imm_post_90 Imm_post_92_m Imm_post_90_m Imm_m i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\td1_is.xls", replace label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)') sortvar(EB_post_92_m EB_post_90_m EB_post_92 EB_post_90) keep(EB_post_92_m EB_post_90_m EB_post_92 EB_post_90)
drop EB_post_92_m EB_post_90_m Imm_post_92_m Imm_post_90_m EB_m Imm_m

*** Selection+Outcomes by age

gen EB_post_92_y = EB_post_92 * (immigration_age<=34)
gen EB_post_90_y = EB_post_90 * (immigration_age<=34)
gen Imm_post_92_y = Imm_post_92 * (immigration_age<=34)
gen Imm_post_90_y = Imm_post_90 * (immigration_age<=34)
gen EB_y = EB * (immigration_age<=34)
gen young = (immigration_age<=34)

svy, subpop(sample): reg edu_years EB_post_92 EB_post_90 EB_post_92_y EB_post_90_y EB_y Imm_post_92 Imm_post_90 Imm_post_92_y Imm_post_90_y young i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\td1_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)') sortvar(EB_post_92_y EB_post_90_y EB_post_92 EB_post_90) keep(EB_post_92_y EB_post_90_y EB_post_92 EB_post_90)

drop EB_post_92_y EB_post_90_y Imm_post_92_y Imm_post_90_y EB_y young

*** Selection+Outcomes by Sov/Sat

svy, subpop(sample): reg edu_years Sov_post_92 Sov_post_90 EB_post_92 EB_post_90 Imm_post_92 Imm_post_90 i.birth_country `controls_sel' i.year
outreg2 using "$path\Output\Israel\td1_is.xls", append label stats(coef se) nonotes dec(3) addstat("Subpop Obs", `e(N_sub)') sortvar(Sov_post_92 Sov_post_90 EB_post_92 EB_post_90) keep(Sov_post_92 Sov_post_90 EB_post_92 EB_post_90)

erase "$path\Output\Israel\td1_is.txt"








